package com.mrd.gtimp.service.impl;

import com.mrd.exception.QueryException;
import com.mrd.gtimp.business.entity.Declaration;
import com.mrd.gtimp.business.service.DeclarationBiz;
import com.mrd.gtimp.service.ICtmsService;

import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.jws.WebService;

/**
 * Created by lenovo on 2017/10/26.
 */
@WebService(endpointInterface = "com.mrd.gtimp.service.ICtmsService", serviceName = "CtmsService")
@Component
public class CtmsServiceImpl implements ICtmsService {

    @Resource
    private DeclarationBiz declarationBiz;

    @Resource
    private JdbcTemplate jdbcTemplate;

    /**
     * 报关单反确认
     * @param reqNo
     * @return
     */
    @Override
    @Transactional
    public String unConfirm(String reqNo) {
        if(StringUtils.isEmpty(reqNo)){
            return "2";
        }
        try {
            Declaration declaration = declarationBiz.findEntityById(reqNo);
            if(declaration==null){
                return "2";
            }
            String sql = "update t_biz_declaration d set d.confirm_type='0',d.confirm_type_time='' where d.id='"+declaration.getId()+"'";
            jdbcTemplate.update(sql);
//            declarationBiz.excuteSql(sql,null);
//            declarationBiz.updateBySql(sql);
            return "1";
        } catch (QueryException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "2";
    }
}
